<?php
class Material extends Zend_Db_Table
{
	protected $_name ="material";
	protected $_primary = 'material_id';
	
//取得前10个教材	
    public function getTopMaterials(){
          $select = $this->select();
          $select->limit('10');
          $select->order('material_id desc');
          return $this->fetchAll($select)->toArray();
    }
    	
  //取得单个教材方法	
	public function getmaterialBymaterial_id($material_id){
	      $select = $this->select();
          $select->where("material_id=".$material_id);
          return $this->fetchAll($select)->toArray();
	}
	
   //更新教材
    public function updatematerialBymaterial_id($array,$material_id){

		$db = $this->getAdapter();
		$where=$db->quoteInto('material_id = ?', $material_id);
		$this->update($array, $where);
        return true;
	}
	
  //删除教材
     public function delmaterialBymaterial_id($material_id){
         $where = 'material_id = '. $material_id;
         $this->delete($where);
         return true;
    }
    
   // 取得所有教材  
    public function getAllMaterials($page,$perpage,$search_name){
          $where = "1=1";
          if($search_name!=""){
              $where.=" and name like '%$search_name%'";
          }
          $select = $this->select();
          $select->where($where);
          if($page!=""){
          $select->limitPage($page,$perpage);
          }
          $select->order('material_id desc');
          return $this->fetchAll($select)->toArray();
    }
}	